package cn.quevo.cube.provide.define.validate;

import cn.quevo.core.spring.util.WebUtils;
import cn.quevo.cube.provide.define.entity.dto.CubeColumnDto;

import java.util.LinkedHashMap;

/**
 * 字段验证抽象实现
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/14 5:41 PM
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
public abstract class AbstractColumnTypeValidate implements ColumnTypeValidate {
    protected final static String EXT = "custom_";

    @Override
    public void validate(CubeColumnDto cubeColumnDto) {
        /*ColumnTypeCode type = ColumnTypeCode.valueOf(cubeColumnDto.getColumnTypeCd());
        switch (type) { // 基本类型验证
            case BIGINT:
            case NUMERIC:
                cubeColumnDto.setMinLength(null);
                cubeColumnDto.setMaxLength(null);
                break;
            case DATE:
            case TIME:
            case ENUM:
                cubeColumnDto.setMinLength(null);
                cubeColumnDto.setMaxLength(null);
                cubeColumnDto.setMinValue(null);
                cubeColumnDto.setMaxValue(null);
                cubeColumnDto.setDecimalNum(null);
                break;
            default:
                cubeColumnDto.setMinValue(null);
                cubeColumnDto.setMaxValue(null);
                cubeColumnDto.setDecimalNum(null);
                break;
        }*/
        cubeColumnDto.setExts(new LinkedHashMap<>());
        this.checked(cubeColumnDto);
    }

    @Override
    public String getCustomParam(String key) {
        return WebUtils.getHttpServletRequest().getParameter(EXT + key);
    }

    protected abstract void checked(CubeColumnDto cubeColumnDto);
}
